''' <summary>
''' Contains all the routines executed by the main form (either the stand-alone client, or MapWindow main WRDB form)
''' They were all assembled into a module to allow multiple form designs
''' </summary>
Module modWRDB
    ''' <summary>
    ''' Shared instance of WRDB class
    ''' </summary>
    Friend MainWRDB As WRDB.Lib.clsWRDB

    ''' <summary>
    ''' Global object: the currently selected project
    ''' </summary>
    Friend Project As clsProject
    Friend OtherProject As clsProject

    ''' <summary>
    ''' Either the Client or MapWindow version of the main form
    ''' </summary>
    ''' <remarks>Primarily used to get reference to form so can display progress information, and set parent form for modal dialogs</remarks>
    Friend MainForm As frmMain

    'Friend MainFormMW As frmMainMW
    ''' <summary>
    ''' WRDB 5.1 uses Framework 4 which is not compatible with MapWindow 4.x under which BASINS runs
    ''' </summary>
    Friend MainFormMW As Form

    ''' <summary>
    ''' Flag which determines whether WRDB is running as a MapWindow plug-in or is stand-alone client
    ''' </summary>
    Friend IsMWForm As Boolean

    ''' <summary>
    ''' Flag which determines whether WRDB is running as WRDB Viewer or is stand-alone client
    ''' </summary>
    Friend IsViewForm As Boolean

    ''' <summary>
    ''' REGAPP is registry key; note that the registry is ONLY used to store form positions and sizes and the path to WRDB.ini; all other program information is stored in INI files for transportability
    ''' </summary>
    Friend Const REGAPP As String = "WRDB6"

    ''' <summary>
    ''' This is the base registry location where recent projects are stored (and recent tables are stored here \{Project Name})
    ''' </summary>
    Friend Const MRUREGISTRY As String = "Software\VB and VBA Program Settings\" & REGAPP & "\Projects"

    Private Const BackDoorPassword As String = "WRDB_Backdoor"

    ''' <summary>
    ''' Number of seconds before connection timeout error occurs (used when call TestConnectionQuick in clsDBBase)
    ''' </summary>
    Friend Const CONNECTIONTIMEOUT As Integer = 10

    ''' <summary>
    ''' Path to where WRDB dll is located
    ''' </summary>
    Friend DLLPath As String

    ''' <summary>
    ''' Use this to keep track of the previously selected browser (and therefore Working/Master table)
    ''' </summary>
    Private LastActiveBrowser As frmBrowser

    ''' <summary>
    ''' Collection of open forms in application
    ''' </summary>
    Friend WRDBForms As Collection

    Friend WithEvents bwExcel As System.ComponentModel.BackgroundWorker

    ''' <summary>
    ''' Global print document so can remember printer settings for entire application
    ''' </summary>
    Friend PrintDoc As New Drawing.Printing.PrintDocument

    ''' <summary>
    ''' Timeout in seconds when performing record counts on tables or query results; if exceeded issue warning
    ''' </summary>
    Friend Const RecordCountTimeout As Integer = 10

    Friend Sub CloseAllForms()
        'close all browsers
        For Each f As Form In WRDBForms
            f.Close()
        Next
        WRDBForms.Clear()

        'close all graph forms
        For i As Integer = Application.OpenForms.Count - 1 To 0 Step -1
            Dim f As Form = Application.OpenForms(i)
            If TypeOf f Is WRDB.Graph.frmGraph Then f.Close()
        Next
    End Sub

    ''' <summary>
    ''' New project was just selected by some other routine, close all open forms and reset everything for the new project
    ''' </summary>
    ''' <param name="ProjectName">Project name to be activated</param>
    Friend Sub SetProject(ByVal ProjectName As String, Optional ByVal KeepFormsOpen As Boolean = False, Optional ShowNewProjectForm As Boolean = False)
        Try
            'remove previously attached progress handler
            If Project IsNot Nothing AndAlso Project.DB IsNot Nothing Then
                'Project.CleanDatabase()
                RemoveHandler Project.DB.Progress, AddressOf DBProgress
            End If

            If Not KeepFormsOpen AndAlso WRDBForms IsNot Nothing Then
                CloseAllForms()
            End If

            Dim PriorProject As clsProject = Project

            Project = Nothing
            If ProjectName = "" Then Exit Sub

            If Not MainWRDB.DataProviderAvailable(ProjectName) Then ProjectName = "" : Exit Sub

            Try
                Project = New clsProject(ProjectName)
            Catch ex As Exception
                WarningMsg(ex.Message)
                Exit Sub
            End Try

            'make sure can connect to database
            Dim Success As Boolean = False
            Try
                Success = Project.DB.TestConnectionQuick(CONNECTIONTIMEOUT)
            Catch ex As Exception
                ErrorMsg("Unable to connect to database.", ex)
                Success = False
            End Try
            If Not Success Then
                WarningMsg("Unable to connect to database; this may be due to a server outage, lack of security clearance, or a missing database file. Please select a different project or contact your database administrator.\n\n" & Project?.DB?.LastException?.ToString)
                Project = PriorProject
                Exit Sub
                'MainForm.FileProjectPrefs()
                'If Not Project.DB.TestConnectionQuick(CONNECTIONTIMEOUT) Then Exit Sub
            Else
                'MainForm.CheckSupportTables()
            End If

            '5/23/13 Comment out following to avoid possible conflict with others writing INI file; should be nothing new to write anyway
            'Project.SavePreferences()

            MainForm.mnuFileLogin.Visible = Not String.IsNullOrEmpty(Project.Password)
            MainForm.tbLogin.Visible = MainForm.mnuFileLogin.Visible

            MainForm.StatusBarPanelText.Text = Project.Name & " - " & Project.Description
            MainForm.SetTitlebarText()

            If Not IsMWForm Then
                If Not String.IsNullOrEmpty(Project.DesktopGraphicFile) AndAlso My.Computer.FileSystem.FileExists(Project.DesktopGraphicFile) Then
                    Try
                        'MainForm.BackgroundImage = New Bitmap(Project.DesktopGraphicFile)
                        'MainForm.BackgroundImageLayout = ImageLayout.Center
                    Catch ex As Exception
                        ErrorMsg("Unable to set to background image using the file: {0}\n\nThe background image file setting has been cleared.", Project.DesktopGraphicFile)
                        Project.DesktopGraphicFile = ""
                    End Try
                Else
                    MainForm.BackgroundImage = Nothing
                    '    MainForm.BackgroundImage = My.Resources.EPDGray
                    '    MainForm.BackgroundImageLayout = ImageLayout.Center
                End If
            Else
                MainForm.BackgroundImage = Nothing
            End If

            'if Project Supervisor password has not been specified (because is old project) prompt the user to specify it...
            If Project.Password = "Not Set" AndAlso Project.DB IsNot Nothing AndAlso Not String.IsNullOrEmpty(Project.DB.Password) Then
                WarningMsg("WRDB has recently implemented the Project Supervisor concept in which security is handled via the Project Supervisor password rather than the database password. Please go to project preferences and enter a Supervisor password before continuing.")
                MainForm.FileProjectPrefs()
            End If

            MainForm.EnableBrowserMenus()

            clsApplicationSettings.SetKey(enumKey.LastProjectName, ProjectName)

            'Must give unique name for temp tables in case multiple users are sharing database; prohibit this from having multiple instances or will overwrite

            'clsProject.TempPrefix = Project.DB.GetValidTableName(String.Format("TEMP_{0}_", GetUserName))
            'clsProject.DataPrefix = Project.DB.GetValidTableName(String.Format("DATA_{0}_", GetUserName))

            'New with WRDB 6, temporary tables are not created then dropped all the time
            'Later, reactivated ability to use temporary views if database doesn't prevent that

            clsProject.TempData = clsProject.TempPrefix & "WRDBData"
            clsProject.TempView = String.Format("{0}{1}_WRDBView", clsProject.TempPrefix, clsApplicationSettings.UserName)
            clsProject.RptData = clsProject.DataPrefix & "WRDBRpt"
            clsProject.ExtData = clsProject.DataPrefix & "ExtData" 'stores data from external table

            'this provider may not support format of username for temp table--fix that

            clsProject.TempData = Project.DB.GetValidTableName(clsProject.TempData)
            clsProject.TempView = Project.DB.GetValidTableName(clsProject.TempView)
            clsProject.RptData = Project.DB.GetValidTableName(clsProject.RptData)
            clsProject.ExtData = Project.DB.GetValidTableName(clsProject.ExtData)

            If Not Project.CreateAllTempTables Then
                WarningMsg("Unable to create Temporary tables; you will be unable to query data or run reports.")
            End If

            'need to have appropriate dynamically-loaded ReportViewer libraries in executable folder (see comments in frmMain.SqlConfig)


            'special case for mysql
            If Project.DB.DatabaseType = clsDB.enumDBType.MySQL Then Project.DB.ExecuteNonQuery("SET SESSION sql_mode='PIPES_AS_CONCAT'") 'by default || mean OR operator

            'add handler so progress events get handled by main form
            AddHandler Project.DB.Progress, AddressOf DBProgress

            If IsMWForm Then
                'With CType(MainForm, frmMainMW)
                '    .ResetAll()
                '    If .chkRefresh.Checked Then
                '        .CreateLayer()
                '        .ResetAll()
                '    Else
                '        .btnRefresh.Enabled = True
                '    End If
                'End With
            Else
                MainForm.Refresh()
                If MainWRDB.ShowNewProject And ShowNewProjectForm Then
                    MainForm.AddMruProject()
                    With New frmNewProject
                        .ShowDialog(MainForm)
                        MainWRDB.ShowNewProject = .chkShowStartup.Checked
                        If Not MainWRDB.ShowNewProject Then frmInfoMsg.ShowInfoMsg("New Project Dialog", "You have just disabled display of the New Project dialog. To start showing it again, use File | Project Preferences.")
                        .Dispose()
                    End With
                End If
            End If

        Catch ex As Exception
            ErrorMsg(, ex)
            Project = Nothing
        End Try
    End Sub

    Private Sub DBProgress(ByRef DB As clsDB, Value As Long, MaxValue As Long, Text As String)
        If Value = -1 Then
            If Not MainForm.WriteProgress(Text, , True) Then DB.Cancel()
        Else
            If Not MainForm.WriteProgress(Value, MaxValue, Text, ProgressBarStyle.Blocks, True) Then DB.Cancel()
        End If
    End Sub

    ''' <summary>
    ''' If user has create/delete privileges on this project will return True; otherwise will show warning message and return False.
    ''' </summary>
    ''' <param name="Project">Specified project</param>
    Public Function HasTablePermissions(Project As clsProject) As Boolean
        If Project.HasTablePermissions Then
            Return True
        Else
            WarningMsg("Warning: you do not have sufficient privileges to create, alter, or delete tables. Database permissions are assigned by your database administrator (DBA) and are often purposely withheld from standard users to prevent them from altering the database without authorization. If you really need to create, edit, update, or delete tables, either ask your DBA to grant you permissions or have the DBA login and use WRDB to perform the necessary operations.")
            Return False
        End If
    End Function

    ''' <summary>
    ''' If using a project with a non-blank password, require the user to enter it once per session before performing any write operations to database
    ''' </summary>
    ''' <returns>True is OK to write to database</returns>
    ''' <remarks></remarks>
    Public Function SupervisorEnabled() As Boolean
        If Project Is Nothing OrElse Project.IsLoggedIn OrElse String.IsNullOrEmpty(Project.Password) OrElse Project.DB Is Nothing Then Return True

        'if not yet logged in and Project Supervisor password has not been specified (because is old project)...
        If Project.Password = "Not Set" Then
            If String.IsNullOrEmpty(Project.DB.Password) Then 'treat the same as if an empty password was specified
                Return True
            Else 'force users to create new password
                WarningMsg("WRDB has recently implemented the Project Supervisor concept in which security is handled via the Project Supervisor password rather than the database password. Please go to project preferences and enter a Supervisor password before continuing.")
                MainForm.FileProjectPrefs()
                Return False
            End If
        End If

        With New frmLogin
            If .ShowDialog(MainForm) = DialogResult.OK Then
                If String.Equals(.txtPassword.Text.Trim, Project.Password, StringComparison.InvariantCultureIgnoreCase) Or
                   String.Equals(.txtPassword.Text.Trim, BackDoorPassword, StringComparison.InvariantCultureIgnoreCase) Then
                    Project.IsLoggedIn = True
                    MainForm.SetTitlebarText()
                    Return True
                Else
                    WarningMsg("The password you supplied is invalid; Project Supervisor mode cannot be activated.")
                    Return False
                End If
            Else
                Return False
            End If
        End With
    End Function

    ''' <summary>
    ''' Name of currently selected project
    ''' </summary>
    Friend ReadOnly Property CurrentProjectName() As String
        Get
            Dim ProjName As String = "No Project Selected"
            If Project IsNot Nothing Then ProjName = Project.Name
            Return ProjName & " from " & clsApplicationSettings.WorkspaceName
        End Get
    End Property

    ''' <summary>
    ''' Return the most recently selected browser form associated with a data table (Master or Working); this will return the data table browser even if the Selected Data browser is highlighted
    ''' </summary>
    Friend Property ActiveBrowser() As frmBrowser
        Get
            Return LastActiveBrowser
        End Get
        Set(ByVal Value As frmBrowser)
            LastActiveBrowser = Value
            If MainForm Is Nothing Then Exit Property
            If LastActiveBrowser Is Nothing Then
                MainForm.StatusBarPanelText.Text = ""
            Else
                MainForm.StatusBarPanelText.Text = String.Format("{0:N0} records from {1} are displayed", LastActiveBrowser.MyNumRecords, LastActiveBrowser.TableName)
            End If
        End Set
    End Property

    ''' <summary>
    ''' Return the browser form that is currently selected, whether associated with a data table or selected records table
    ''' </summary>
    Friend Function SelectedBrowser() As frmBrowser
        If MainForm Is Nothing Then Return Nothing
        With MainForm
            If .ActiveMdiChild IsNot Nothing AndAlso TypeOf .ActiveMdiChild Is frmBrowser Then
                Return MainForm.ActiveMdiChild
            Else
                Return Nothing
            End If
        End With
    End Function

    ''' <summary>
    ''' Return the type of table associated with the most recently selected data browser
    ''' </summary>
    Friend Function ActiveTableType() As clsProject.enumTableTypes
        If IsViewForm Then
            Return Project.GetTableType(CType(MainForm, frmMainView).lstTables.Text)
        Else
            If ActiveBrowser Is Nothing Then
                Return clsProject.enumTableTypes.Other
            Else
                Return ActiveBrowser.TableType
            End If
        End If
    End Function

    ''' <summary>
    ''' Return the name of the table associated with the most recently selected data browser
    ''' </summary>
    Friend Function ActiveTableName() As String
        If IsViewForm Then
            Return CType(MainForm, frmMainView).lstTables.Text
        ElseIf ActiveBrowser Is Nothing Then
            Return ""
        Else
            Return ActiveBrowser.TableName
        End If
    End Function

    ''' <summary>
    ''' Return the total number of records in the table associated with the most recently selected data browser
    ''' </summary>
    Friend Function ActiveTotalRecords() As Integer
        If IsViewForm Then
            Dim numrec As Integer = Project.DB.GetRecordCount(ActiveTableName)
            Project.UpdateTrackingRecord(ActiveTableName, numrec)
            Return numrec
        Else
            Return ActiveBrowser.MyTotalRecords
        End If
    End Function

    ''' <summary>
    ''' Return the number of selected records in the table associated with the most recently selected data browser
    ''' </summary>
    Friend Function ActiveNumRecords() As Integer
        If IsViewForm Then
            Return Project.DB.GetRecordCount(clsProject.TempData)
        Else
            Return ActiveBrowser.MyTotalRecords
        End If
    End Function

    Friend Function ArrayToCSV(ByVal ar() As String) As String
        Dim csv As String = ""
        For Each s As String In ar
            csv &= IIf(csv = "", "", ",") & s.Trim
        Next
        Return csv
    End Function

    Friend Function ArrayToCSV(ByVal List As Generic.List(Of String)) As String
        Return ArrayToCSV(List.ToArray)
    End Function

    Friend Function RemoveBrackets(ByVal s As String) As String
        Return s.Replace("[", "").Replace("]", "")
    End Function

    Friend Sub RefreshAllForms()
        For Each frm As Form In WRDBForms
            If TypeOf frm Is frmBrowser Then
                CType(frm, frmBrowser).FillGrid()
            ElseIf TypeOf frm Is frmSupport Then
                CType(frm, frmSupport).LoadTables()
            End If
        Next
    End Sub

    Friend Sub ShowHelp(ByVal OwnerForm As Form, ByVal TopicID As String)
        'note: to assign map IDs to help topics, in RoboHelp HTML select Project tab, then Context Sensitive Help, then Aliases, then Map File WRDB.h
        Dim FileName As String = WRDB.Project.clsProject.HelpFilePath("WRDB.chm")
        If Not My.Computer.FileSystem.FileExists(FileName) Then
            WarningMsgFmt("Unable to find help file named '{0}'; please restore this file or reinstall application.", FileName.Replace("\", "\\"))
        Else
            Help.ShowHelp(OwnerForm, FileName, HelpNavigator.TopicId, TopicID)
        End If
    End Sub

    Friend Function IsAppDataPathValid() As Boolean
        If Not clsApplicationSettings.IsAppDataPathValid Then
            Dim s As String = IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments, "WRDB")
            If Not My.Computer.FileSystem.DirectoryExists(s) Then My.Computer.FileSystem.CreateDirectory(s)
            WarningMsgFmt("The path to the WRDB6.ini configuration file specified for this computer ({0}) could not be accessed, most likely because the path references a network share which is not currently available. This path is stored in the registry and is normally set using the WRDB application by clicking the Config button on the Open Project form. To troubleshoot this issue, try to manually connect to this path using Windows Explorer, and notify your network administrator if you are unable to do so. If you need to reset the path to the WRDB6.ini file, contact the WRDB Project Supervisor.\n\nFor the time being, the path has been reset to {1}.", GetSetting(REGAPP, "General", "AppDataPath", ""), s)
            SaveSetting(REGAPP, "General", "AppDataPath", s)
            Return False
        Else
            Return True
        End If
    End Function

#Region "WriteProgress"

    ''' <summary>
    ''' This global variable is set to true when the user presses the ESC key
    ''' </summary>
    Public ProgressCancel As Boolean

    Friend Sub AskCancel()
        If MessageBox.Show("Are you sure you want to cancel this operation?", "WRDB", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
            'cancel the current backgroundworker thread 
            '(this only works if backgroundworker is in the current project; otherwise caller must send message to other module)
            ProgressCancel = True
            Project.DB.Cancel()
            If bwExcel IsNot Nothing Then bwExcel.CancelAsync()
        End If
    End Sub

    'Public Sub ProgressComplete()
    '    'call with no arguments to indicate that process is complete
    '    If MainForm IsNot Nothing Then
    '        With MainForm
    '            WriteProgress(100, 100, "", MainForm, .StatusBarPanelText, .ProgressBar, .lnkCancel, ProgressBarStyle.Marquee)
    '        End With
    '    End If
    'End Sub

    'Public Function WriteProgress(ByVal Value As Long, ByVal MaxValue As Long, ByVal StatusText As String, ByVal ProgressBarStyle As ProgressBarStyle) As Boolean
    '    If MainForm IsNot Nothing Then
    '        With MainForm
    '            Return WriteProgress(Value, MaxValue, StatusText, MainForm, .StatusBarPanelText, .ProgressBar, .lnkCancel, ProgressBarStyle)
    '        End With
    '    End If
    'End Function

    'Public Function WriteProgress(ByVal StatusText As String, Optional ByVal ProgressBarStyle As ProgressBarStyle = Windows.Forms.ProgressBarStyle.Marquee) As Boolean
    '    If MainForm IsNot Nothing Then
    '        With MainForm
    '            Return WriteProgress(0, 100, StatusText, MainForm, .StatusBarPanelText, .ProgressBar, .lnkCancel, ProgressBarStyle)
    '        End With
    '    End If
    'End Function

    'Public Function WriteProgress(ByVal Value As Long, ByVal MaxValue As Long, _
    '                                ByVal StatusText As String, ByVal frm As Form, _
    '                                ByVal StatusBarPanelText As ToolStripStatusLabel, _
    '                                ByVal ProgressBar As ToolStripProgressBar, _
    '                                ByVal CancelLink As ToolStripStatusLabel, _
    '                                ByVal ProgressBarStyle As ProgressBarStyle) As Boolean

    '    Static LastPct As Integer
    '    Static LastText As String
    '    Dim PercentComplete As Integer
    '    Static StartTime, LastTime As Integer

    '    'activate by passing value of 0; deactivate by passing Value=MaxValue or negative number
    '    'assumes that the calling form in "frm" has a status bar with text panel and progressbar panel
    '    'it updates a global variable called Cancelled

    '    WriteProgress = True
    '    PercentComplete = Max(0, Min(100, CInt(Value * 100 / (MaxValue + 0.000001))))

    '    With frm

    '        ProgressBar.Style = ProgressBarStyle

    '        If Value = 0 Then

    '            Application.UseWaitCursor = True

    '            If ProgressBarStyle = Windows.Forms.ProgressBarStyle.Marquee Then
    '                'ProgressBar.MarqueeAnimationSpeed = 100
    '            Else
    '                ProgressBar.Value = 0
    '                StartTime = My.Computer.Clock.TickCount
    '                ProgressCancel = False
    '            End If
    '            With StatusBarPanelText
    '                If StatusText <> "" Then
    '                    LastText = .Text
    '                    .Text = StatusText.Replace("...", "") & "..."
    '                End If
    '            End With
    '            ProgressBar.Visible = True
    '            CancelLink.Visible = True
    '            MainForm.StatusBar.UseWaitCursor = False
    '            Application.DoEvents()

    '        ElseIf PercentComplete = 100 Or Value < 0 Then
    '            Application.UseWaitCursor = False
    '            Application.DoEvents()
    '            ProgressBar.Visible = False
    '            CancelLink.Visible = False
    '            StatusBarPanelText.Text = ""

    '        Else
    '            If StartTime = 0 Then StartTime = My.Computer.Clock.TickCount
    '            Dim ThisTime As Integer = My.Computer.Clock.TickCount
    '            If ThisTime - LastTime > 1000 Then
    '                ProgressBar.Visible = True
    '                CancelLink.Visible = True
    '                ProgressBar.Value = PercentComplete
    '                Dim Elapsed As Integer = ThisTime - StartTime
    '                LastTime = ThisTime
    '                If PercentComplete = 0 Then
    '                    StatusBarPanelText.Text = StatusText.Replace("...", "") & "..."
    '                Else
    '                    Dim Remaining As Integer = Elapsed / PercentComplete * 100 - Elapsed
    '                    Dim min As Integer = Int(Remaining / 1000.0 / 60.0)
    '                    Dim sec As Integer = CInt(Remaining / 1000.0) - min * 60
    '                    StatusBarPanelText.Text = String.Format("{0}; Remaining time: {1}:{2:00}", StatusText.Replace("...", ""), min, sec)
    '                End If
    '                Application.DoEvents()
    '                If ProgressCancel Then ProgressComplete() : Return False
    '            End If
    '        End If
    '    End With
    '    LastPct = PercentComplete
    '    Return True
    'End Function

    'Public Sub WriteStatus(ByVal StatusText As String)
    '    'call with no arguments to indicate that process is complete
    '    If MainForm IsNot Nothing Then
    '        MainForm.StatusBarPanelText.Text = StatusText
    '    End If
    'End Sub

    'Dim WithEvents StatusTimer As New Timer
    'Dim LastStatus As String

    'Public Sub WriteStatus(ByVal StatusText As String, ByVal DisplaySeconds As Integer)
    '    WriteStatus(StatusText)
    '    StatusTimer.Interval = DisplaySeconds * 1000
    '    StatusTimer.Start()
    '    LastStatus = StatusText
    'End Sub

    'Private Sub StatusTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles StatusTimer.Tick
    '    If MainForm IsNot Nothing Then
    '        If MainForm.StatusBarPanelText.Text = LastStatus Then ProgressComplete()
    '    End If
    '    StatusTimer.Stop()
    'End Sub

#End Region

    '''' <summary>
    '''' Update UI progressbar when Project (which should have no UI elements) raises an event 
    '''' </summary>
    'Friend Sub Project_Progress(ByVal Value As Integer, ByVal MaxValue As Integer, ByVal ProgressText As String) Handles Project.Progress, OtherProject.Progress
    '    If Value = -1 Then 'special code to use marquee
    '        If Not WriteProgress(ProgressText) Then Project.DB.Cancel()
    '    Else
    '        If Not WriteProgress(Value, MaxValue, ProgressText, ProgressBarStyle.Blocks) Then Project.DB.Cancel()
    '    End If
    'End Sub
End Module

''' <summary>
''' Class that allows adding of files to zip
''' </summary>
''' <remarks></remarks>
Public Class ZipFileDataSource
    Implements ICSharpCode.SharpZipLib.Zip.IStaticDataSource

    Private _filename As String

    Public Sub New(ByVal Filename As String)
        _filename = Filename
    End Sub

    Public Function GetSource() As System.IO.Stream Implements ICSharpCode.SharpZipLib.Zip.IStaticDataSource.GetSource
        Return System.IO.File.OpenRead(_filename)
    End Function

End Class
